﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using Medianamik.Core.Sugar;
using Medianamik.UI.Web.MVP.View;

namespace Medianamik.UI.Web.Shop
{
    public partial class ShopOrders : ModuleViewWithGrid<IOrders>, IOrders
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FilterButton.Click += OnFilterButton;

            if(!Page.IsPostBack)
            {
                BindDateTypeDropDownList();
            }
        }

        protected virtual void BindDateTypeDropDownList()
        {
            DateTypeDropDownList.DataSource = GetDateType();
            DateTypeDropDownList.DataBind();
        }


        public override IEnumerable<ListItem> Status
        {
            get { return ContentStatesList.Items.Cast<ListItem>(); }
            set
            {
                ContentStatesList.Items.AddRange(value.ToArray());
            }
        }

        protected List<ListItem> GetDateType()
        {
            var dateTypes = new List<ListItem>();

            dateTypes.Add(new ListItem
              {
                  Value = ShopSchema.Order.Columns.PurchaseDate,
                  Text = "PurchaseDate".Translate("Shop")
              });

            dateTypes.Add(new ListItem
            {
                Value = ShopSchema.Order.Columns.ShippedDate,
                Text = "ShippedDate".Translate("Shop")
            });

            dateTypes.Insert(0, new ListItem(""));

            return dateTypes;
        }

        void OnFilterButton(object sender, EventArgs e)
        {
            OnFilter();
        }

        public override DateTime? SelectedStartDateTime
        {
            get { return null; }
            set { }
        }

        public override DateTime? SelectedEndDateTime
        {
            get { return null; }
            set { }
        }

        public override string Keywords
        {
            get { return null; }
            set { }
        }

        public override string ListingPageUrl
        {
            get { return Pages.OrderList; }
        }

        public override IMedianamikGrid Grid
        {
            get { return (IMedianamikGrid)OrdersGrid; }
        }

        public override string EditPageUrl
        {
            get
            {
                return Pages.EditInvariantCulture;
            }
        }

        public override Guid ModuleNodeId
        {
            get
            {
                return PageIds.OrderList;
            }
        }

        public override string BreadcrumbTrail
        {
            get { return Breadcrumbs.Text; }
            set { Breadcrumbs.Text = value; }
        }

        public override Guid BaseTypeId
        {
            get
            {
                return TypeIds.Order;
            }
        }

        public DateTime? StartingDate
        {
            get { return StartingDateTextBox.SelectedDate; }
        }

        public DateTime? EndingDate
        {
            get { return EndingDateTextBox.SelectedDate; }
        }

        public string TransactionId
        {
            get { return TransactionIdTextBox.Text; }
        }

        public string SelectedDateColumnName
        {
            get {return DateTypeDropDownList.SelectedValue; }
        }

        public string ClientName
        {
            get { return ClientNameTextBox.Text; }
        }

        public string ClientEmail
        {
            get { return ClientEmailTextBox.Text; }
        }

        public string ClientPhoneNumber
        {
            get { return ClientPhoneNumberTextBox.Text; }
        }

        public string SelectedStatus
        {
            get { return ContentStatesList.SelectedValue; }
        }
    }

    public interface IOrders : IModuleViewWithGrid
    {
        DateTime? StartingDate { get; }
        DateTime? EndingDate { get; }
        string TransactionId { get; }
        string SelectedDateColumnName { get; }
        string ClientName { get; }
        string ClientEmail { get; }
        string ClientPhoneNumber { get; }
        string SelectedStatus { get; }
    }
}
